package com.yueqian.web.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionHandleResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView mav = new ModelAndView();
        if (e instanceof CustomException) {
            CustomException exception = (CustomException) e;
            mav.setViewName("error/500");
            mav.addObject("msg", exception.getMessage());
        } else {
            mav.setViewName("error/400");
//            mav.addObject("msg", "网络异常，请稍后再试");
            mav.addObject("msg", e.getMessage());
        }
        return mav;
    }
}
